package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectPojo;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description NursingProjectServiceImpl
 * @Author huangdongye
 * @Date 2025-05-08  11:29
 */
@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> getByPage(NursingProjectPojo pageNursing) {
        PageHelper.startPage(pageNursing.getPageNum(), pageNursing.getPageSize());
        Page<NursingProject> byPage = nursingProjectMapper.selectByPage(pageNursing);
        PageResponse<NursingProjectVo> pageResponse = PageResponse.of(byPage, NursingProjectVo.class);
        return pageResponse;
    }

    @Override
    public void addNursingProject(NursingProjectVo nursingProject) {
        nursingProject.setCreateTime(LocalDateTime.now());
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProjectMapper.addNursingProject(nursingProject);
    }

    @Override
    public NursingProjectVo getNursingProjectById(Long id) {
        return nursingProjectMapper.getNursingProjectById(id);
    }

    @Override
    public void updateNursingProject(NursingProjectVo npv) {
        NursingProject nursingProject = BeanUtil.toBean(npv, NursingProject.class);
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProjectMapper.updateNursingProject(nursingProject);
    }

    @Override
    public void updateSwitch(Long id, int status) {
        nursingProjectMapper.updateSwitch(id, status);
    }

    @Override
    public void deleteNursingProject(Long id) {
        nursingProjectMapper.deleteNursingProject(id);
    }

    @Override
    public List<NursingProjectVo> allNursingProject() {
        List<NursingProjectVo> result =  nursingProjectMapper.allNursingProject();
        return result;
    }
}
